#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int rank(int n)
{
    int ans, i;

    ans = 1;
    for (i = 0; i < n; i++) {
        ans *= 10;
    }

    return ans;
}

int main (int argc, char const* argv[])
{
    int t, p, ccnt, a, b, i, j, num, len, test, arr[12], ans;
    char str[12];
    int matrix[20000000];

    scanf("%d", &t);
    ccnt = 1;
    while (ccnt <= t) {
        scanf("%d %d", &a, &b);

        for (i = a; i <= b; i++) {
            matrix[i] = 0;
        }

        for (num = a; num <= b; num++) {
            if (matrix[num] > 1) {
                continue;
            }
            sprintf(str, "%d", num);
            len = strlen(str);
            for (i = 0; i < len; i++) {
                arr[i] = str[len - i - 1] - '0';
            }

            for (i = 0; i < len; i++) {
                test = 0;
                for (j = 0, p = i; j < len - 1; j++, p++%len) {
                    test += arr[i] * rank(j);
                }
                if (test >= a && test <= b && test != num &&
                        matrix[test] == 0) {
                    matrix[num] = 1; matrix[test] = 2;
                }
            }
        }

        ans = 0;
        for (i = a; i <= b; i++) {
            if (matrix[i] == 1) {
                ans++;
            }
        }

        printf("Case #%d: %d\n", ccnt, ans);

        ccnt++;
    }

    return 0;
}
